<?php
/**
 * The control file of index module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class user extends control
{
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * The index page.
     * 
     * @access public
     * @return void
     */
    public function index($date="")
    {
        if(!$date){
            $date = date('Y',time());
        }

        $startDate1    = "{$date}-01-01";
        $startDate2    = "{$date}-02-01";
        $startDate3    = "{$date}-03-01";
        $startDate4    = "{$date}-04-01";
        $startDate5    = "{$date}-05-01";
        $startDate6    = "{$date}-06-01";
        $startDate7    = "{$date}-07-01";
        $startDate8    = "{$date}-08-01";
        $startDate9    = "{$date}-09-01";
        $startDate10    = "{$date}-10-01";
        $startDate11    = "{$date}-11-01";
        $startDate12    = "{$date}-12-01";
        $this->view->data1 = $this->loadModel('statistics')->getcategorysum($startDate1);

        $this->view->data2 = $this->loadModel('statistics')->getcategorysum($startDate2);
        $this->view->data3 = $this->loadModel('statistics')->getcategorysum($startDate3);
        $this->view->data4 = $this->loadModel('statistics')->getcategorysum($startDate4);
        $this->view->data5 = $this->loadModel('statistics')->getcategorysum($startDate5);
        $this->view->data6 = $this->loadModel('statistics')->getcategorysum($startDate6);
        $this->view->data7 = $this->loadModel('statistics')->getcategorysum($startDate7);
        $this->view->data8 = $this->loadModel('statistics')->getcategorysum($startDate8);
        $this->view->data9 = $this->loadModel('statistics')->getcategorysum($startDate9);
        $this->view->data10 = $this->loadModel('statistics')->getcategorysum($startDate10);
        $this->view->data11 = $this->loadModel('statistics')->getcategorysum($startDate11);
        $this->view->data12 = $this->loadModel('statistics')->getcategorysum($startDate12);

        $this->view->category = $this->user->getprocess();
        $this->view->links = $this->loadModel('setting')->getlink();
        $this->view->img = $this->loadModel('setting')->getbanner();

        $this->view->title = $this->lang->statistics->index;
        $this->view->years = $this->user->getlang();
        $this->view->time = $date;
        $this->view->nowyears = date('Y',time());
        $this->view->bigcategory = $this->loadModel('statistics')->getbigcatecory();

        $this->display();

    }

    public function punit($date=""){

        if(!$date){
            $date = date('Y',time());
        }

        $this->view->punit = $this->loadModel('statistics')->getappraisal($date);
        $this->view->years = $this->user->getlang();
        $this->view->time = $date;
        $this->view->nowyears = date('Y',time());
        $this->view->links = $this->loadModel('setting')->getlink();
        $this->view->img = $this->loadModel('setting')->getbanner();

        $this->display();
    }

    public function munit($starttime=""){

        $this->view->links = $this->loadModel('setting')->getlink();
        $this->view->img = $this->loadModel('setting')->getbanner();

        $date = time();
        $this->view->title = $this->lang->statistics->index;
        $this->view->date = date('Y',$date);

        $date = date('Y',time());
        $this->view->startDate1    = "01-01";
        $this->view->startDate2    = "02-01";
        $this->view->startDate3    = "03-01";
        $this->view->startDate4    = "04-01";
        $this->view->startDate5    = "05-01";
        $this->view->startDate6    = "06-01";
        $this->view->startDate7    = "07-01";
        $this->view->startDate8    = "08-01";
        $this->view->startDate9    = "09-01";
        $this->view->startDate10    = "10-01";
        $this->view->startDate11    = "11-01";
        $this->view->startDate12    = "12-01";

        if(!$starttime){
            $nowdate = date('Y-m',time());
            $starttime    = "{$nowdate}-01";
        }

        $this->view->unit = $this->loadModel('statistics')->getunit($starttime);
        $ytime = date('Y',strtotime($starttime));
        $moth = date('m',strtotime($starttime));
        $time = $ytime;
        $this->view->month = $moth;
        $this->view->time = $time;
        $this->view->nowyears = date('Y',time());
        $this->view->category = $this->loadModel('statistics')->getbigcatecory();

        $this->display();
    }

    public function people($unit="",$date=""){

        $this->view->links = $this->loadModel('setting')->getlink();
        $this->view->img = $this->loadModel('setting')->getbanner();


        $this->view->category1 = $this->loadModel('statistics')->getbigcatecory();

        $startDate    = "{$date}-01-01";
        $this->view->users = $this->loadModel('statistics')->pstatis($unit,$startDate);
        $cname = $this->loadModel('statistics')->getunitname($unit);
        $time = $date.'年';
        $this->view->time = $time;
        $this->view->cname = $cname;
        $this->display();
    }

    public function pcenter()
    {

        $this->view->category = $this->user->getprocess();
        $this->view->links = $this->loadModel('setting')->getlink();
        $this->view->img = $this->loadModel('setting')->getbanner();

        $date = time();
        $this->view->title = $this->lang->statistics->index;
        $this->view->date = date('Y',$date);
        $this->view->bigcategory = $this->loadModel('statistics')->getbigcatecory();

        $date = date('Y',time());
        $startDate1    = "{$date}-01-01";
        $startDate2    = "{$date}-02-01";
        $startDate3    = "{$date}-03-01";
        $startDate4    = "{$date}-04-01";
        $startDate5    = "{$date}-05-01";
        $startDate6    = "{$date}-06-01";
        $startDate7    = "{$date}-07-01";
        $startDate8    = "{$date}-08-01";
        $startDate9    = "{$date}-09-01";
        $startDate10    = "{$date}-10-01";
        $startDate11    = "{$date}-11-01";
        $startDate12    = "{$date}-12-01";
        $this->view->data1 = $this->loadModel('statistics')->getcategorysum($startDate1);

        $this->view->data2 = $this->loadModel('statistics')->getcategorysum($startDate2);
        $this->view->data3 = $this->loadModel('statistics')->getcategorysum($startDate3);
        $this->view->data4 = $this->loadModel('statistics')->getcategorysum($startDate4);
        $this->view->data5 = $this->loadModel('statistics')->getcategorysum($startDate5);
        $this->view->data6 = $this->loadModel('statistics')->getcategorysum($startDate6);
        $this->view->data7 = $this->loadModel('statistics')->getcategorysum($startDate7);
        $this->view->data8 = $this->loadModel('statistics')->getcategorysum($startDate8);
        $this->view->data9 = $this->loadModel('statistics')->getcategorysum($startDate9);
        $this->view->data10 = $this->loadModel('statistics')->getcategorysum($startDate10);
        $this->view->data11 = $this->loadModel('statistics')->getcategorysum($startDate11);
        $this->view->data12 = $this->loadModel('statistics')->getcategorysum($startDate12);

        $this->display();

    }


    public function login()
    {
        if($this->user->isLogon()){
            $this->locate($this->createLink('process', 'index'));
        }
        $this->view->links = $this->loadModel('setting')->getlink();
        $this->view->img = $this->loadModel('setting')->getbanner();
        $this->display();
    }

    public function userprofile(){
        $user = $_SESSION['user'];
        $this->view->user = $user;
        $this->view->title = $this->lang->user->profile;
        $this->display();
    }

    public function changepsd(){
        $user = $_SESSION['user'];
        $this->view->user = $user;
        $this->display();
    }

    public function changepassword(){
        $originalPassword = $this->post->originalPassword;
        $password = $this->post->password;
        $queren = $this->user->changepsd($originalPassword,$password);

        echo json_encode($queren);
        exit;
    }

    public function checklogin(){
        $policenumber = $this->post->policenumber;
        $password = $this->post->password;
        $data = $this->user->login($policenumber,$password);
        echo $data;
        exit;
    }

    public function logout(){
        session_destroy();
        $this->locate($this->createLink('user','login'));
    }

}
